package aufgabe2;

public class Match implements Comparable<Match> {
	
	private double sx, sy, ex, ey, weight, score = -1;
	private Match prec = null;

	public Match(double sx, double ex, double sy, double ey, double weight) {
		this.sx = sx;
		this.sy = sy;
		this.ex = ex;
		this.ey = ey;
		this.weight = weight;
	}

	public double getSx() {
		return sx;
	}

	public double getSy() {
		return sy;
	}

	public double getEx() {
		return ex;
	}

	public double getEy() {
		return ey;
	}
	
	public double getWeight() {
		return weight;
	}	

	public Match getPrec() {
		return prec;
	}

	public void setPrec(Match prec) {
		this.prec = prec;
	}
	
	public double getScore() {		
		return (score != -1) ? score : (prec == null) ? weight : prec.getScore() + weight ;
	}
	
	public void setScore(double score) {		
		this.score = score;
	}

	/**
	 * << function
	 * 
	 * @param m match f'
	 * 
	 * @return boolean
	 */
	public boolean precedes(Match m) {
		return (ex < m.getSx() && ey < m.getSy());
	}
	
	@Override
	public int compareTo(Match m) {
		if (ex == m.getEx()) return 0;
		else if (ex < m.getEx()) return -1;
		
		return 1;
	}
	
	public String toString() {
		return sx+" "+sy+" "+ex+" "+ey+" "+weight;
	}
	
	public static Match createMatchFromString(String s) {
		String[] parts = s.split(" ");		
		return new Match(Double.parseDouble(parts[0]), Double.parseDouble(parts[1]), Double.parseDouble(parts[2]), Double.parseDouble(parts[3]), Double.parseDouble(parts[4]));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Match m1 = new Match(10, 100, 500, 590, 88.5);
		Match m2 = new Match(110, 200, 600, 690, 90);
		
		System.out.println(m1.precedes(m2));
		System.out.println(m2.precedes(m1));
	}



}
